package easy;

import java.util.HashMap;
import java.util.Map;

public class Solution_2053 {

    public String kthDistinct(String[] arr, int k) {
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < arr.length; i++) {
            if (map.containsKey(arr[i])) {
                map.put(arr[i], -1);
            } else {
                map.put(arr[i], i);
            }
        }
        boolean[] flags = new boolean[1001];
        for (String s : map.keySet()) {
            Integer index = map.get(s);
            if (index >= 0) {
                flags[index] = true;
            }
        }
        for (int i = 0, count = 0; i < flags.length; i++) {
            if (flags[i]) {
                count++;
                if (count == k) {
                    return arr[i];
                }
            }
        }
        return "";
    }

    public static void main(String[] args) {
        Solution_2053 model = new Solution_2053();
        System.out.println(model.kthDistinct(new String[]{"d", "b", "c", "b", "c", "a"}, 2));
        System.out.println(model.kthDistinct(new String[]{"aaa", "aa", "a"}, 1));
        System.out.println(model.kthDistinct(new String[]{"a", "b", "a"}, 3));
    }
}
